package com.woniuxy.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dao.ManagerDao;
import com.woniuxy.entity.Manager;
import com.woniuxy.entity.ManagerDto;
import com.woniuxy.service.ManagerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description: TODO(用一句话描述这个类的作用)
 * @Author 18452
 * @Date 2021/4/26 13:11
 */
@Service
public class ManagerServiceImpl implements ManagerService {
    @Resource
    private ManagerDao managerDao;

    @Override
    public PageInfo<Map<String,String>> select(ManagerDto managerDto) {

        PageHelper.startPage(managerDto.getPage(),managerDto.getLimit());
        List<Map<String, String>> maps = managerDao.select(managerDto.getEditForm());
        PageInfo<Map<String,String>> pageInfo = new PageInfo<>(maps);
        return pageInfo;
    }

    @Override
    public boolean selectPass(String account, String password) {
        String pass = managerDao.selectPass(account);
        if (password.equals(pass)){
            return true;
        }
        return false;
    }

    @Override
    public String insert(Manager manager) {
        int row = managerDao.insert(manager);
        if(row == 0){
            return "defeated";
        }
        return "success";
    }

    @Override
    public String update(Manager manager) {
        int row = managerDao.update(manager);
        if(row == 0){
            return "defeated";
        }
        return "success";
    }

    @Override
    public String delete(int id) {
        int row = managerDao.delete(id);
        if(row == 0){
            return "defeated";
        }
        return "success";
    }

}
